from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-02-28 14:06:20.769642
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 28, Feb, 2021
Time: 14:06:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4576
Nobs: 216.000 HQIC: -47.2958
Log likelihood: 2500.89 FPE: 1.63388e-21
AIC: -47.8639 Det(Omega_mle): 1.08725e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.472766 0.135618 3.486 0.000
L1.Burgenland 0.074128 0.069605 1.065 0.287
L1.Kärnten -0.214954 0.059042 -3.641 0.000
L1.Niederösterreich 0.149245 0.158435 0.942 0.346
L1.Oberösterreich 0.254363 0.141178 1.802 0.072
L1.Salzburg 0.208412 0.074722 2.789 0.005
L1.Steiermark 0.098327 0.100841 0.975 0.330
L1.Tirol 0.132554 0.067747 1.957 0.050
L1.Vorarlberg -0.013465 0.061416 -0.219 0.826
L1.Wien -0.146588 0.130939 -1.120 0.263
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.472712 0.162863 2.903 0.004
L1.Burgenland 0.008786 0.083588 0.105 0.916
L1.Kärnten 0.351472 0.070904 4.957 0.000
L1.Niederösterreich 0.104668 0.190264 0.550 0.582
L1.Oberösterreich -0.124889 0.169539 -0.737 0.461
L1.Salzburg 0.199542 0.089733 2.224 0.026
L1.Steiermark 0.201948 0.121099 1.668 0.095
L1.Tirol 0.140137 0.081357 1.722 0.085
L1.Vorarlberg 0.156513 0.073754 2.122 0.034
L1.Wien -0.497372 0.157244 -3.163 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.311941 0.062689 4.976 0.000
L1.Burgenland 0.098705 0.032175 3.068 0.002
L1.Kärnten -0.019788 0.027292 -0.725 0.468
L1.Niederösterreich 0.086618 0.073236 1.183 0.237
L1.Oberösterreich 0.298454 0.065259 4.573 0.000
L1.Salzburg 0.006629 0.034540 0.192 0.848
L1.Steiermark -0.009536 0.046614 -0.205 0.838
L1.Tirol 0.075868 0.031316 2.423 0.015
L1.Vorarlberg 0.098823 0.028390 3.481 0.000
L1.Wien 0.059187 0.060526 0.978 0.328
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219222 0.067969 3.225 0.001
L1.Burgenland -0.005242 0.034884 -0.150 0.881
L1.Kärnten 0.019114 0.029591 0.646 0.518
L1.Niederösterreich 0.044757 0.079405 0.564 0.573
L1.Oberösterreich 0.385877 0.070755 5.454 0.000
L1.Salzburg 0.087454 0.037449 2.335 0.020
L1.Steiermark 0.180816 0.050539 3.578 0.000
L1.Tirol 0.040429 0.033954 1.191 0.234
L1.Vorarlberg 0.085347 0.030781 2.773 0.006
L1.Wien -0.058487 0.065624 -0.891 0.373
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.508980 0.135248 3.763 0.000
L1.Burgenland 0.059444 0.069415 0.856 0.392
L1.Kärnten 0.013714 0.058881 0.233 0.816
L1.Niederösterreich -0.017742 0.158002 -0.112 0.911
L1.Oberösterreich 0.143766 0.140792 1.021 0.307
L1.Salzburg 0.065233 0.074518 0.875 0.381
L1.Steiermark 0.109357 0.100565 1.087 0.277
L1.Tirol 0.209901 0.067562 3.107 0.002
L1.Vorarlberg 0.027368 0.061249 0.447 0.655
L1.Wien -0.109843 0.130581 -0.841 0.400
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190537 0.097435 1.956 0.051
L1.Burgenland -0.017450 0.050007 -0.349 0.727
L1.Kärnten -0.007525 0.042419 -0.177 0.859
L1.Niederösterreich 0.071658 0.113828 0.630 0.529
L1.Oberösterreich 0.396975 0.101429 3.914 0.000
L1.Salzburg -0.013104 0.053684 -0.244 0.807
L1.Steiermark -0.012989 0.072449 -0.179 0.858
L1.Tirol 0.179402 0.048673 3.686 0.000
L1.Vorarlberg 0.044505 0.044125 1.009 0.313
L1.Wien 0.175227 0.094073 1.863 0.063
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.242875 0.125496 1.935 0.053
L1.Burgenland 0.046191 0.064409 0.717 0.473
L1.Kärnten -0.039049 0.054635 -0.715 0.475
L1.Niederösterreich -0.040214 0.146610 -0.274 0.784
L1.Oberösterreich -0.074601 0.130640 -0.571 0.568
L1.Salzburg 0.060325 0.069145 0.872 0.383
L1.Steiermark 0.395300 0.093314 4.236 0.000
L1.Tirol 0.461757 0.062691 7.366 0.000
L1.Vorarlberg 0.155671 0.056832 2.739 0.006
L1.Wien -0.205433 0.121166 -1.695 0.090
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.123681 0.150790 0.820 0.412
L1.Burgenland 0.021645 0.077391 0.280 0.780
L1.Kärnten -0.070686 0.065647 -1.077 0.282
L1.Niederösterreich 0.202729 0.176159 1.151 0.250
L1.Oberösterreich -0.017939 0.156971 -0.114 0.909
L1.Salzburg 0.254056 0.083081 3.058 0.002
L1.Steiermark 0.142020 0.112122 1.267 0.205
L1.Tirol 0.048975 0.075326 0.650 0.516
L1.Vorarlberg 0.064877 0.068287 0.950 0.342
L1.Wien 0.234158 0.145587 1.608 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.571654 0.081148 7.045 0.000
L1.Burgenland -0.037623 0.041648 -0.903 0.366
L1.Kärnten -0.016154 0.035328 -0.457 0.647
L1.Niederösterreich -0.000427 0.094800 -0.005 0.996
L1.Oberösterreich 0.306205 0.084474 3.625 0.000
L1.Salzburg 0.020201 0.044710 0.452 0.651
L1.Steiermark -0.006316 0.060339 -0.105 0.917
L1.Tirol 0.077248 0.040537 1.906 0.057
L1.Vorarlberg 0.120568 0.036749 3.281 0.001
L1.Wien -0.027827 0.078348 -0.355 0.722
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.136909 0.037461 0.199087 0.248035 0.059625 0.124607 -0.037238 0.169512
Kärnten 0.136909 1.000000 0.003573 0.196505 0.166441 -0.121830 0.151252 0.010082 0.316766
Niederösterreich 0.037461 0.003573 1.000000 0.281583 0.070616 0.239033 0.159011 0.046670 0.351983
Oberösterreich 0.199087 0.196505 0.281583 1.000000 0.291897 0.280477 0.104749 0.071234 0.134096
Salzburg 0.248035 0.166441 0.070616 0.291897 1.000000 0.134486 0.054268 0.087195 -0.002745
Steiermark 0.059625 -0.121830 0.239033 0.280477 0.134486 1.000000 0.119590 0.113721 -0.112875
Tirol 0.124607 0.151252 0.159011 0.104749 0.054268 0.119590 1.000000 0.181128 0.162752
Vorarlberg -0.037238 0.010082 0.046670 0.071234 0.087195 0.113721 0.181128 1.000000 0.024765
Wien 0.169512 0.316766 0.351983 0.134096 -0.002745 -0.112875 0.162752 0.024765 1.000000